import {getLevelList} from "../../../api";


const levelListStore = (set)=>{
    return {
        levelList:[],
        fetchGetLevelList:async ()=>{
            const {data} = await getLevelList();
            set({levelList: data.data})
            localStorage.setItem("levelList",JSON.stringify(data.data))
        },
        getLocalLevelList:()=>{
           return  JSON.parse(localStorage.getItem("levelList"));
        },
        getLevelById:(id)=>{
           const levelList=  JSON.parse(localStorage.getItem("levelList"));
           const filter = levelList.filter(item=>item.id==id);
            return filter.length > 0 ? filter[0] : {};
        }
    }
}

export default levelListStore;